package cn.laixueit.service.impl;

import cn.laixueit.mapper.MessageMapper;
import cn.laixueit.pojo.Message;
import cn.laixueit.pojo.MessageExample;
import cn.laixueit.service.MessageService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private MessageMapper messageMapper;

    @Override
    public List<Message> findMessageOrderLimit6() {

        MessageExample example = new MessageExample();
        example.setOrderByClause("createtime desc");
        MessageExample.Criteria criteria = example.createCriteria();
        criteria.andClosetimeGreaterThanOrEqualTo(new Date());

        Page<Object> page = PageHelper.startPage(1, 6);
        List<Message> messageList = messageMapper.selectByExample(example);
        PageInfo<Message> pageInfo = new PageInfo<>(messageList);
        return pageInfo.getList();
    }
}
